<?php
define('COMMENT_REF_BBS'	,	'BBS');
define('COMMENT_REF_REVIEW'	,	'REVIEW');
class Cl_Comment extends WdkClass 
{
	protected
		/******************************************************/
		//	원본 테이블 정보
		/******************************************************/
		$comment_seq			= 0					,	//	
		$fk_ref_seq				= 0					,	//	
		$fk_user_seq			= 0					,	//	
		$comment_ref_type		= COMMENT_REF_BBS	,	//	
		$comment_index			= 0					,	//	
		$comment_depth			= 0					,	//	
		$comment_score			= 0					,	//	
		$comment_user_name		= ''				,	//	
		$comment_user_passwd	= ''				,	//	
		$comment_content		= ''				,	//	
		$comment_secure_flag	= 'F'				,	//	
		$comment_insert_time	= 0					,	//	
		$comment_del_flag		= 'F'				;	//	
		/******************************************************/
		//	추가 정보
		/******************************************************/
	
	/**
	 * 	
	 */
	function __construct()
	{
		parent::__construct();
		self::getDbo();
	}
	
	/**
	 *	
	 */
	public function __init($data)
	{
		parent::__init($data);
		self::dformat();
	}
	
	/**
	 *	
	 */
	public function load($comment_seq)
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		self::__init($dbo->cLoad($comment_seq));
	}
	
	/**
	 *	
	 */
	public function dformat()
	{
		
	}
	
	/**
	 * 
	 */
	public function autoUpdate($log='')
	{
		if((int)$this->comment_seq > 0)
		{
			$this->update($log);
		}
		else
		{
			$this->insert($log);
		}
	}
	
	/**
	 *	
	 */
	public function insert($log='Insert')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		$pwd = Wdk::helper('Passwd');
		/*------------------------------------------------------------*/
		if((int)$this->fk_user_seq == 0)
		{
			$this->comment_passwd	= $pwd->encrypt($this->comment_passwd);
		}
		
		$this->comment_insert_time	= time();
		$this->comment_del_flag		= 'F';
		
		$data = array(	'fk_ref_seq'			=>	$this->fk_ref_seq,
						'fk_user_seq'			=>	$this->fk_user_seq,
						'comment_ref_type'		=>	$this->comment_ref_type,
						'comment_index'			=>	$this->comment_index,
						'comment_depth'			=>	$this->comment_depth,
						'comment_score'			=>	$this->comment_score,
						'comment_user_name'		=>	$this->comment_user_name,
						'comment_user_passwd'	=>	$this->comment_user_passwd,
						'comment_content'		=>	$this->comment_content,
						'comment_secure_flag'	=>	$this->comment_secure_flag,
						'comment_insert_time'	=>	$this->comment_insert_time,
						'comment_del_flag'		=>	$this->comment_del_flag
					);
		$this->comment_seq = $dbo->insert($data);
		$this->backup($log);
	}
	
	/**
	 * 
	 */
	public function update($log='update')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		$pwd = Wdk::helper('Passwd');
		/*------------------------------------------------------------*/
		if((int)$this->fk_user_seq == 0)
		{
			$this->comment_passwd	= $pwd->encrypt($this->comment_passwd);
		}
		
		$data = array(	'comment_score'			=>	$this->comment_score,
						'comment_user_name'		=>	$this->comment_user_name,
						'comment_user_passwd'	=>	$this->comment_user_passwd,
						'comment_content'		=>	$this->comment_content,
						'comment_secure_flag'	=>	$this->comment_secure_flag
					);
		$dbo->update($data, array("comment_seq = ".$this->comment_seq));
		$this->backup($log);
	}
	
	/**
	 * 
	 */
	public function delete($log='delete')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$dbo->delete(array("comment_seq = ".$this->comment_seq));
		$this->backup($log);
	}
	
	/**
	 *	
	 */
	private function backup($log='')
	{
// 		/*------------------------------------------------------------*/
// 		$dbo = self::getDbo();
// 		/*------------------------------------------------------------*/
// 		$dbo->log($this->user_seq, $log, $this->backup_data);
	}
	
	/**
	 * 
	 */
	public function getDbo()
	{
		return Wdk::model(substr(__CLASS__, 3));
	}
}